import { defineStore } from 'pinia/dist/pinia'

export const useUserStore = defineStore('user', {
	state: () => {
		return {
			username: '',
			account: '',
			avatar: '',
			token: '',
			role: 0,
			credit: 0,
		}
	},
	getters: {},
	actions: {
		LOGIN (user) {
			this.$patch({
				username: user.username,
				account: user.account,
				avatar: user.avatar,
				token: user.token,
				credit: user.credit,
				role: user.role,
			})
		},
		LOGOUT () {
			this.$patch({
				username: '',
				account: '',
				avatar: '',
				token: '',
				credit: 0,
				role: 0,
			})
		},
	},
	persist: {
		enabled: true,
	},
})
